package cn.cdeden.knowledge.controller.formDoc;

import cn.cdeden.common.core.domain.R;
import cn.cdeden.common.core.utils.page.TableDataInfo;
import cn.cdeden.knowledge.domain.SysFormDocTemp;
import cn.cdeden.knowledge.domain.SysFormDocTempDto;
import cn.cdeden.knowledge.domain.SysFormDocTempQueryParam;
import cn.cdeden.knowledge.service.SysFormDocTempService;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import java.util.Set;

/**
* @author Chen
* @date 2023-12-26
**/
@RestController
@RequiredArgsConstructor
//@Api(tags = "表单文档模板管理")
@RequestMapping("/api/sysFormDocTemp")
public class SysFormDocTempController {

    private final SysFormDocTempService sysFormDocTempService;

    @GetMapping
//    @Log("查询表单文档模板")
//    @ApiOperation("查询表单文档模板")
    public R query(SysFormDocTempQueryParam query, Pageable pageable){
        TableDataInfo<SysFormDocTempDto> formDataDtoPageInfo = sysFormDocTempService.queryAll(query, pageable);
        return R.ok(formDataDtoPageInfo);
    }

    @GetMapping("formJson")
//    @Log("查询单个表单JSON")
//    @ApiOperation("查询单个表单JSON")
    public R queryFormJsonById(@RequestParam("formId") Long formId){
        return  R.ok(sysFormDocTempService.getById(formId));
    }

    @GetMapping("/addPreviews")
//    @Log("添加浏览次数")
//    @ApiOperation("添加浏览次数")
    public R addPreviews(@RequestParam("formId") Long formId){
        SysFormDocTemp sysFormDocTemp = sysFormDocTempService.getById(formId);
        if (sysFormDocTemp.getPreviews() != null){
            sysFormDocTemp.setPreviews(sysFormDocTemp.getPreviews()+1);
        }else {
            sysFormDocTemp.setPreviews(1);
        }
//        enterpriseTemplateTreeService.addPreviewByFromId(formId,1);
        return R.ok(sysFormDocTempService.updateById(sysFormDocTemp));
    }

    @PostMapping(value = "/add")
//    @Log("新增表单文档模板")
//    @ApiOperation("新增表单文档模板")
    public R create(SysFormDocTempDto resources){
        return R.ok(sysFormDocTempService.insert(resources));
    }

//    @Log("修改名称信息")
//    @ApiOperation("修改名称信息")
    @PostMapping(value = "/update")
    public R update(SysFormDocTempDto resources){
        sysFormDocTempService.updateById(resources);
        return R.ok();
    }

//    @Log("修改表单文档模板")
//    @ApiOperation("修改表单文档模板")
    @PostMapping(value = "/updateFormJson")
    public R updateFormJson(SysFormDocTempDto resources){
        sysFormDocTempService.updateById(resources);
        return R.ok();
    }


//    @Log("删除表单文档模板")
//    @ApiOperation("删除表单文档模板")
    @DeleteMapping(value = "/delete")
    public R delete(@RequestBody Set<Long> ids) {
        sysFormDocTempService.removeByIds(ids);
        return R.ok() ;
    }

//    /**
//     * 挂载流程表单
//     */
////    @Log("挂载表单文档模板")
////    @ApiOperation("挂载表单文档模板")
//    @PostMapping("/addDeployForm")
//    public R addDeployForm(@RequestBody SysDeployForm sysDeployForm) {
//        return new R<>(sysDeployFormService.insertSysDeployForm(sysDeployForm),HttpStatus.OK);
//    }
}
